<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
<script>
    (function(){
        function Itcast(selector){
            return new Itcast.fn.init(selector);
        }
        Itcast.fn = Itcast.prototype = {
            init: function ( selector){

            }
        };

        Itcast.fn.init.prototype = Itcast.fn;
        window.Itcast = window.I = Itcast;







        function map ( array, callback ) {
            var i, k,
                    res = [],
                    tmp;
            if ( isArrayLike( array ) ) {
                // 使用 for 循环
                for ( i= 0; i < array.length; i++ ) {
                    tmp = callback( array[ i ], i );
                    if ( tmp !== undefined ) {
                        res.push( tmp );
                    }
                }
            } else {
                // 使用 for-in 循环
                for ( k in array ) {
                    tmp = callback( array[ k ], k );
                    if ( tmp !== undefined ) {
                        res.push( tmp );
                    }
                }
            }
            return res;
        }

        function isArrayLike (array){

            var length = array && array.length;
            return typeof length === "number" && length >=0;
        };
        function each ( array, callback ) {
            var i, k;
            if ( isArrayLike( array ) ) {
                // 使用 for 循环
                for ( i= 0; i < array.length; i++ ) {
                    if( callback.call( array[ i ], i, array[ i ] ) === false ) break;
                    // if( callback.apply( array[ i ],[ i, array[ i ]] ) === false ) break;
                }
            } else {
                // 使用 for-in 循环
                for ( k in array ) {
                    if( callback.call( array[ i ], k , array[ k ] ) === false ) break;
                }
            }
            return array;
        }

        function select(selector){
            return document.querySelectorAll( selector );
        }

        function Itcast(selector){
            //初始化this是伪数组

            var list = select(selector);
            this.length=0;
            [].push.apply(this,list);//讲lst中每个元素一一加到this中并且会自增length属性

            //return this 可加可不加 默认返回this
        }
        function I(selector){
            return new Itcast(selector);
        }
    })();
</script>
</html>